<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13-打印倒三角形</title>
</head>
<body>
    <script>
        /* 
            *****
            ****
            ***
            **
            *
            思路：双重for 循环，外层控制行，内层控制列
            i(外层)       num (内层)的最大值
            0           5
            1           4
            2           3
            3           2
            4           1
            
            i + num = 5
            num = 5 - i;
        */
        for (let i=0; i<5; i++){
            let start = '';
            for (j = 0; j<5-i; j++){
                start = start + '*';
                }
                console.log(start);
            }
            
            console.log('----------------');
        /* 
            *
            **
            ***
            ****
            *****
        思路：双重for 循环，外层控制行，内层控制列
            i(外层)     num (内层)的最大值
            0           1
            1           2
            2           3
            3           4
            4           5
            num = i+1
        */
            for (let i=0; i<5; i++){
                let star = '';
                for (let j=0; j<i+1; j++){
                    star = star + '*';
                }
                console.log(star);
            }

            console.log('----------------------');
        /* 
             1111*
             111**
             11***
             1****
             *****
        思路：双重for 循环，外层控制行，内层控制列
        i(外层)      空格      num (内层)的最大值
            0         4             1
            1         3             2
            2         2             3
            3         1             4
            4         0             5
        
        */
       
        for (let i = 0; i < 5; i++) {    // 5次   0 1 2 3 4    i=1 i<=5  1 2 3 4 5
                let star = '';
            for (let j = 0; j < 5 - i; j++) {
                star = star + ' ';
            }
            for (let k = 0; k < i + 1; k++) {
                star = star + '*';
            }
            console.log(star);
        }


     
            
            
































   /*     for (let i = 0; i<5; i++){            //控制三角形行数
           let star = '';
           for (let k = 0; k < 5-i; k++){    //控制三角形列数
               star = star + '*';          //输出五角星作为打印
           }
           console.log(star);
       }

       console.log('----------------');
 */
        /*
            *
            **
            ***
            ****
            *****

           i    j
           0    1
           1    2
           2    3
           3    4
           4    5

        */
  /*   var str='';
    for(var i=1;i<=5;i++){
        for(var j=1; j<=i; j++){
         var str = str +'*';
        }
    str = str + '\n';
    }
    console.log(str);
console.log('----------------');
    var str='';
    for(var i=1;i<=5;i++){
       for(var j=i; j<=5;j++){
          var str=str +'*';
      }
      str=str + '\n';
  }
  console.log(str);
 */

    </script>
</body>
</html>